import { createRouter, createWebHistory } from 'vue-router'
import AdminLayout from '@/views/AdminLayout.vue'
import RolesManagement from '@/views/admin/RolesManagement.vue'
import UserList from '@/views/admin/UserList.vue'
import Dashboard from '@/views/admin/Bashboard.vue'
import LogsManagement from '@/views/admin/LogsManagement.vue'
import Backup from '@/views/admin/ServiceMonitor.vue'
import AdvertiserLayout from '@/views/AdvertiserLayout.vue'
import DeviceOwnerLaout from '@/views/DeviceOwnerLaout.vue'
import DeviceManagement from '@/views/admin/DeviceManagement.vue'
import AdsManagement from '@/views/admin/AdsManagement.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {

      path: '/',
      redirect: '/login' // 添加根路径重定向
    },

    {
      path: '/login',
      name: 'Login',
      component: () => import('@/views/Login.vue'),
    },
    {
      path: '/forgot-password',
      name: 'ForgotPassword',
      component: () => import('@/views/ForgotPassword.vue'),
    },
    {
      path: '/register',
      name: 'Register',
      component: () => import('@/views/Register.vue'),
    },
    {
      path: '/userinfo',
      name: 'UserInfo',
      component: () => import('@/views/UserInfo.vue'),
      meta: { requiresAuth: true }
    },
    {
      path: '/admin',
      component: AdminLayout,
      //meta: { requiresAuth: true, role: 'admin' },
      children: [
        { path: 'roles', component: RolesManagement },
        { path: 'users', component: UserList },
        { path: 'dashboard', component: Dashboard },
        { path: 'logs', component: LogsManagement },
        { path: 'backup', component: Backup },
        { path: 'devices', component: DeviceManagement },
        { path: 'ads', component: AdsManagement },
        {
          path: 'notifications',
          name: 'SendSystemNotification',
          component: () => import('@/views/admin/SendSystemNotification.vue'),
          meta: {
            title: '发送系统通知',
            requiresAuth: true
          }
        },
        {
          path: 'ad-detail/:id',
          name: 'AdDetail',
          component: () => import('@/views/advertiser/AdDetails.vue'),
        },
        {
          path: 'devices/:id',
          component: () => import('@/views/device-owner/DeviceDetail.vue'),
          name: 'DeviceDetails',
          meta: { title: '设备详情' },
          props: true
        },


      ]
    },
    // 广告主路由
    {
      path: '/advertiser',
      component: AdvertiserLayout,
      redirect: '/advertiser/dashboard',
      meta: { requiresAuth: true, role: 2 }, // 广告主角色
      children: [
        {
          path: 'details/:id',
          name: 'ScheduleDetail',
          component: () => import('@/views/advertiser/ScheduleDetail.vue'),
          meta: { title: '排期详情', activeMenu: '/schedule/management' },
          hidden: true
        },
        {
          path: 'dashboard',
          name: 'AdvertiserDashboard',
          component: () => import('@/views/advertiser/Dashboard.vue')
        },
        {
          path: 'ads',
          name: 'AdvertiserAdvertisement',
          component: () => import('@/views/advertiser/MyAds.vue'),
          meta: { title: '我的广告' }
        },
        {
          path: 'notification',
          name: 'AdvertiserNotification',
          component: () => import('@/views/NotificationCenter.vue'),
          meta: { title: '消息中心' }
        },
        {
          path: 'create-ad',
          name: 'AdvertiserCreateAd',
          component: () => import('@/views/advertiser/CreateEditAd.vue')
        },
        {
          path: 'ad-details/:id',
          name: 'AdDetails',
          component: () => import('@/views/advertiser/AdDetails.vue'),
          props: true,
          meta: { title: '广告详情' }
        },
        {
          path: 'edit-ad/:id',
          name: 'EditAd',
          component: () => import('@/views/advertiser/EditAd.vue'),
          props: true,
          meta: { title: '编辑广告' }
        },
        {
          path: "statistics",
          name: "Statistics",
          component: () => import("@/views/advertiser/Statistics.vue"),
          meta: { title: "广告统计" }
        },
        {
          path: 'negotiation',
          component: () => import('@/views/advertiser/NegotiationList.vue'),
          name: 'AdvertiserNegotiationList',
          meta: { title: '协商列表', icon: 'el-icon-chat-line-round' }
        },
        {
          path: 'negotiation/:id',
          component: () => import('@/views/NegotiationDetail.vue'),
          name: 'AdvertiserNegotiationDetail',
          meta: { title: '协商详情', icon: 'el-icon-document' },
          hidden: true
        },
        {
          path: 'chat/:id',
          component: () => import('@/views/advertiser/ChatView.vue'),
          name: 'AdvertiserChat',
          meta: { title: '聊天', icon: 'el-icon-chat-dot-round' },
          hidden: true
        },
        {
          path: 'billing',
          component: () => import('@/views/advertiser/Billing.vue'),
          name: 'AdvertiserBilling',
          meta: { title: '账单', icon: 'el-icon-money' }
          // hidden: true
        },
        {
          path: 'bill/:id',
          component: () => import('@/views/advertiser/BillDetail.vue'),
          name: 'AdvertiserBillDetail',
          meta: { title: '账单详情', icon: 'el-icon-money' },
        },
        {
          path: 'management',
          name: 'ScheduleManagement',
          component: () => import('@/views/advertiser/ScheduleManagement.vue'),
          meta: { title: '排期列表' , icon: 'el-icon-date' }
        }
      ]
    },
    {
      path: '/device-owner',
      component: DeviceOwnerLaout,
      meta: { requiresAuth: true, role: 3 }, // 设备主
      name: 'DeviceOwner',
      children: [
        {
          path: 'schedule-management',
          name: 'DeviceOwnerScheduleManagement',
          component: () => import('@/views/device-owner/ScheduleStatusManagement.vue'),
          meta: {
            title: '排期状态管理',
            requiresAuth: true
          }
        },
        {
          path: 'dashboard',
          component: () => import('@/views/device-owner/Dashboard.vue'),
          name: 'DeviceOwnerDashboard',
          meta: { title: '控制台', icon: 'Monitor', keepAlive: true }
        },
        {
          path: 'notification',
          name: 'Notification',
          component: () => import('@/views/NotificationCenter.vue'),
          meta: { title: '消息中心' }
        },
        {
          path: 'negotiation/:id',
          component: () => import('@/views/NegotiationDetail.vue'),
          name: 'DeviceNegotiationDetail',
          meta: { title: '协商详情', icon: 'el-icon-document' },
          hidden: true
        },
        {
          path: 'devices',
          component: () => import('@/views/device-owner/DeviceList.vue'),
          name: 'DeviceOwnerDevices',
          meta: { title: '设备管理', icon: 'Device', keepAlive: true }
        },
        {
          path: 'negotiations',
          component: () => import('@/views/device-owner/NegotiationList.vue'),
          name: 'DeviceOwnerNegotiations',
          meta: { title: '协商管理', icon: 'ChatLineRound', keepAlive: true }
        },
        {
          path: 'devices/add',
          component: () => import('@/views/device-owner/DeviceForm.vue'),
          name: 'AddDevice',
          meta: { title: '添加设备', activeMenu: '/device-owner/devices' }
        },
        {
          path: 'devices/edit/:id',
          component: () => import('@/views/device-owner/DeviceForm.vue'),
          name: 'EditDevice',
          meta: { title: '编辑设备', activeMenu: '/device-owner/devices' },
          props: true
        },
        {
          path: 'devices/:id',
          component: () => import('@/views/device-owner/DeviceDetail.vue'),
          name: 'DeviceDetail',
          meta: { title: '设备详情', activeMenu: '/device-owner/devices' },
          props: true
        },
        {
          path: 'income',
          component: () => import('@/views/device-owner/income.vue'),
          name: 'Income',
          meta: { title: '收入统计', activeMenu: '/device-owner/income' }
        },
        {
          path: "advertisements",
          component: () => import('@/views/device-owner/Advertisement.vue'),
          name: 'Advertisements',
          meta: { title: '广告市场', activeMenu: '/device-owner/advertisements' }
        },
        // router.js 或 相应的路由文件
        {
          path: 'schedule/create/:id',
          name: 'CreateSchedule',
          component: () => import('@/views/device-owner/CreateSchedule.vue'),
          meta: { requiresAuth: true, role: 'DEVICE_OWNER' }
        },
        {
          path: 'settings',
          name: 'DeviceOwnerSettings',
          component: () => import('@/views/UserInfo.vue'),
          meta: { title: '账户设置', icon: 'Setting' }
        },
        {
          path: 'chat/:id',
          component: () => import('@/views/device-owner/ChatView.vue'),
          name: 'Chat',
          meta: { title: '聊天', icon: 'el-icon-chat-dot-round' },
          hidden: true
        },
      ]
    }
  ],
})

export default router
